package com.shop.cereshop.commons.tencent.im.enums.redpacket;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @description: 红包生命周期枚举
 * @author zdd
 * @date 2025/9/3 11:27
 * @version 1.0
 */
public enum RedPacketLifeCycleEnum {

    // 红包生命周期：1-有效 2-已领完 3-已过期
    EFFECTIVE(1, "有效"),
    COMPLETED(2, "已领完"),
    EXPIRED(3, "已过期");

    private final Integer code;
    private final String msg;

    private static final Map<Integer, RedPacketLifeCycleEnum> CODE_MAP = new HashMap<>();

    static {
        for (RedPacketLifeCycleEnum status : RedPacketLifeCycleEnum.values()) {
            CODE_MAP.put(status.getCode(), status);
        }
    }

    RedPacketLifeCycleEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public static String getMsgByCode(Integer code) {
        if (Objects.isNull(code)) {
            return "";
        }
        RedPacketLifeCycleEnum status = CODE_MAP.get(code);
        return status != null ? status.getMsg() : "";
    }
}
